package zero.tech.games.dn.event;

import com.alibaba.fastjson.JSONObject;

import zero.tech.core.event.EventListener;
import zero.tech.core.event.EventType;
import zero.tech.games.dn.data.DnConfig;
import zero.tech.games.dn.data.DnGameBase;
import zero.tech.games.dn.data.DnRoomCache;
import zero.tech.games.dn.data.DnTimer;
import zero.tech.games.dn.data.entity.DnMultiple;
import zero.tech.games.logic.common.Room;
import zero.tech.games.logic.data.LogicEventType;

public class RoomCreated implements EventListener{

	@Override
	public EventType netEventType() {
		return LogicEventType.ROOM_CREATED;
	}

	@Override
	public void notifyEvent(Object... objs) {
		Room room = (Room) objs[0];
		DnTimer dnTimer=new DnTimer(room.getRoom_id());
		room.setTimer(dnTimer);
		DnRoomCache dnRoomCache=new DnRoomCache(room.getRoom_id());
		room.setRoomCache(dnRoomCache);
		DnConfig dnConfig=JSONObject.parseObject(room.getConfigStr(),DnConfig.class);
		room.setGameConfig(dnConfig);
		DnMultiple dnMultiple = new DnMultiple(dnConfig);
		dnRoomCache.setDn_multiple(dnMultiple);
		DnGameBase dnGameBase=new DnGameBase(room.getRoom_id());
		room.setGameBase(dnGameBase);
	}

	@Override
	public boolean asynchronous() {
		return false;
	}

}
